package com.example.zhaoping.controller;

import com.example.zhaoping.entity.Enterprise;
import com.example.zhaoping.entity.User;
import com.example.zhaoping.serviceImpl.EnterpriseServiceImpl;
import com.example.zhaoping.serviceImpl.UserServiceImpl;
import com.example.zhaoping.util.Result;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController

public class RegController {
    @Resource
    private UserServiceImpl userService;

    @Resource
    private EnterpriseServiceImpl enterpriseService;

    private Result result = new Result();

    /**
     * 用户注册
     * @param
     * @return
     */
    @PostMapping("/user/register")
    public Result<?> regUser(User user){
        if(userService.registerUser(user)==1){
            return result.success("注册成功！");
        }else{
            return result.error("注册失败！");
        }
    }
    @PostMapping("/enterprise/register")
    public Result<?> inster(Enterprise enterprise){
        if(enterpriseService.selectOne(enterprise.getUsername())!=null){
            return result.error("该企业已存在，请前往登录！");
        }else if(enterpriseService.selectByName(enterprise.getName())!=null){
            return result.error("该企业名称已存在，不可重复注册企业！");
        }
        if(enterpriseService.inster(enterprise)==1){
            return result.success("注册成功！");
        }else{
            return result.error("注册失败！");
        }
    }
}
